package com.msblearn.C_007;

import java.util.concurrent.LinkedTransferQueue;

public class T001_TranferQueue {
    public static void main(String[] args) {
        LinkedTransferQueue queue = new LinkedTransferQueue();
        String[] abc = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"};

        new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                try {
                    queue.transfer(i + 1);
                    System.out.print(queue.take());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();

        new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                try {
                    System.out.print(queue.take());
                    queue.transfer(abc[i]);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}
